import React from 'react';
import { Button, Checkbox, Form, Input,notification } from 'antd';
import { leave_application } from '../../../utils/apileave'

function Leaveapplication(props) {
    // 点击提交后
    const onFinish = (values) => {
        console.log('Success:', values);
        var time = new Date
        var times =`${time.getFullYear()}-${time.getMonth()}-${time.getDate()} ${time.getHours()}:${time.getMinutes()}`
        console.log(times)
        // console.log(time)
        // 在这里拿到用户的id，再去创建一个时间组合再一块通过post添加到请假列表里
        var usename = JSON.parse((localStorage.getItem("userinfo")))

        console.log("用户名",usename,usename.name);
        var item ={
            "name": usename.name,
            "reason": values.reason,
            "start": values.start,
            "end": values.end,
            "state": false,
            "text": values.text,
            "submissionTime":times
        }
        leave_application(item).then((res)=>{
            console.log(res)
            notification.success({message:'请假申请已提交!'});
        })
      };
    
    return (
        <div className='leaveapplication'>
            <Form
            name="basic"
            labelCol={{ span: 8 }}
            wrapperCol={{ span: 16 }}
            initialValues={{ remember: true }}
            onFinish={onFinish}
            autoComplete="off"
            >
            <Form.Item
                label="请假类型"
                name="reason"
                rules={[{ required: true, message: 'Please input your username!' }]}
            >
                <Input />
            </Form.Item>
            <Form.Item
                label="起始时间"
                name="start"
                rules={[{ required: true, message: 'Please input your username!' }]}
            >
                <Input />
            </Form.Item>
            <Form.Item
                label="结束时间"
                name="end"
                rules={[{ required: true, message: 'Please input your username!' }]}
            >
                <Input />
            </Form.Item>
            <Form.Item
                label="请假描述"
                name="text"
                rules={[{ required: true, message: 'Please input your username!' }]}
            >
                <Input />
            </Form.Item>

            

            

            <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
                <Button type="primary" htmlType="submit">
                提交
                </Button>
            </Form.Item>
            </Form>
        </div>
    );
}

export default Leaveapplication;